package com.scu.baseline.advice;

import com.scu.baseline.controller.TestLogController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;


@RestControllerAdvice
public class ExceptionAdvice {                 // 全局式异常和错误管理

    // 自定义当前类日志
    private static final Logger sysLog = LoggerFactory.getLogger(ExceptionAdvice.class);

    @ExceptionHandler(Throwable.class)
    public Map<String, Object> errorMessage(Throwable t) {
        // tester
        Map<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg", "ExceptionAdvice 系统服务正忙！请稍后重试");
        map.put("data", t);
        sysLog.error("errorMessage = " + t);
        return map;
    }
}
